﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TCSilverlight.ServiceReference1;

namespace TCSilverlight
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            //BindingProducts();
            BindingImages();
        }


        private void BindingImages()
        {
            TCSilverlight.ServiceReference1.WCFServiceClient serviceClient = new WCFServiceClient();
            serviceClient.GetTestImagesCompleted += new EventHandler<GetTestImagesCompletedEventArgs>(serviceClient_GetTestImagesCompleted);

            serviceClient.GetTestImagesAsync();

        }


        void serviceClient_GetTestImagesCompleted(object sender, GetTestImagesCompletedEventArgs e)
        {
            try
            {
                coverFlow.ItemsSource = e.Result;
               
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        private void BindingProducts()
        {
            TCSilverlight.ServiceReference1.WCFServiceClient serviceClient = new WCFServiceClient();
            serviceClient.GeTblProductsCompleted += new EventHandler<GeTblProductsCompletedEventArgs>(serviceClient_GeTblProductsCompleted);

            serviceClient.GeTblProductsAsync();
            
        }

        void serviceClient_GeTblProductsCompleted(object sender, GeTblProductsCompletedEventArgs e)
        {
            try
            {
                coverFlow.ItemsSource = e.Result;
                //List<DataItem> listdata = new List<DataItem>();
                //List<tblProduct> list = new List<tblProduct>();
                //list = e.Result.Cast<tblProduct>().ToList();
                //for (int i = 0; i < list.Count; i++)
                //{
                //    DataItem tempDataItem = new DataItem();
                //    tempDataItem.ImageSourceId = new Uri("../Images/CoverFlow/Paris_1.jpg", UriKind.Relative);
                //}

                

            }
            catch (Exception ex)
            {

                throw ex;
            }
            
            //throw new NotImplementedException();
        }

        public class DataItem
        {
            private Uri imageSourceId;
            private string productName;
            private string productDescription;
            private string productPrice;

            public Uri ImageSourceId
            {
                get { return imageSourceId; }
                set { imageSourceId = value; }
            }

            public string ProductName
            {
                get { return productName; }
                set { productName = value; }
            }

            public string ProductDescription
            {
                get { return productDescription; }
                set { productDescription = value; }
            }

            public string ProductPrice
            {
                get { return productPrice; }
                set { productPrice = value; }
            }
        }
    }
}
